import os
import re

# 要修改的倍数
n=2

filepath = ''
tempfile = ''
for root,dirs,files in os.walk(os.getcwd()):
	for file in files:
		if file.endswith("m3u8"):
			filepath = os.path.join(root,file)
			tempfile = os.path.join(root,'temp_index1.m3u8')
			break
print("要修改的索引文件：%s"%filepath)
if filepath:
	lines = ''
	with open(filepath,'r',encoding='utf-8') as file:
		lines = file.readlines()
	with open(tempfile,'w',encoding='utf-8') as file:
		for line in lines:
			if line.startswith('#'):
				if "EXTINF" in line:
					durTime = re.compile(':(.*?),')
					durTime = durTime.findall(line)[0]
					durTime = float(durTime)*n
					durTime = str(durTime).rstrip('0')
					if durTime.endswith('.'):
						durTime = durTime[:-1]
					rlt,num = re.subn(':(.*?),',':%s,'%(durTime),line)
					line = rlt
			file.write(line)